package cn.topevery.garden.dal.logic.warning;

import cn.topevery.garden.dal.logic.base.WarningBase;
import cn.topevery.garden.entity.dto.ManholeReportDTO;
import cn.topevery.garden.framework.util.WarningConfigUtil;
import hw.topevery.basis.dal.logic.SysClassExtLogic;
import hw.topevery.basis.dal.logic.SysClassLogic;
import hw.topevery.basis.entity.po.SysClass;
import hw.topevery.basis.entity.po.SysClassExt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author ：peng.tian
 * @date ：Created in 2021/10/28 21:10
 * @description：
 */
@Component
public class ManholeWarning extends WarningBase {
    @Override
    public String getClassId() {
        return "7B4E7E50-E080-44FA-A0D7-786CFCF593BB";
    }

    @Override
    public String getFacilitiesType() {
        return "23ace7c4-9123-44cf-91a1-7e546c5ea2f9";
    }

    @Override
    public String getWarningType() {
        return "1E72EA75-D710-412B-BE6A-EC2C199C35AD";
    }

    @Autowired
    SysClassExtLogic sysClassExtLogic;

    @Autowired
    SysClassLogic sysClassLogic;

    public void check(ManholeReportDTO dto) throws Exception {
        StringBuilder warningDesc = new StringBuilder();

        SysClass voltageClass= sysClassLogic.getEntityByDataId("4BA7E952-2FA5-4334-BBEC-7AF1E025CF85");
        SysClassExt voltage = sysClassExtLogic.getEntityByDataId("4BA7E952-2FA5-4334-BBEC-7AF1E025CF85");

        SysClass leanClass= sysClassLogic.getEntityByDataId("2520AB32-36A8-4617-AEA8-CAA2C81237A0");
        SysClassExt lean = sysClassExtLogic.getEntityByDataId("2520AB32-36A8-4617-AEA8-CAA2C81237A0");
        boolean isWarning = false;

        if(WarningConfigUtil.Judge(dto.getVoltage().doubleValue(),Double.parseDouble(voltage.unit),voltageClass.remark)) {
//        if (dto.getVoltage() >= Double.parseFloat(voltage.unit)) {//按值判断
            isWarning = true;
            warningDesc.append("电压预警，电压为").append(dto.getVoltage()).append("V\n");
            this.setSmallClassId("4BA7E952-2FA5-4334-BBEC-7AF1E025CF85");
        }

        if(WarningConfigUtil.Judge(dto.getLeanValue().doubleValue(),Double.parseDouble(lean.unit),leanClass.remark)) {
//        if (dto.getLeanValue() >= Integer.parseInt(lean.unit)) {//按值判断
            isWarning = true;
            warningDesc.append("井盖发生倾斜，倾斜角度为").append(dto.getLeanValue()).append("°");
            this.setSmallClassId("2520AB32-36A8-4617-AEA8-CAA2C81237A0");
        }
        if (isWarning) {
            sendWarning(dto.getDeviceCode(),warningDesc.toString(),dto.getId());
        }
    }
}
